﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

namespace CMSLibrary.TagsCreate.CustomFunction.Inside
{
    /// <summary>
    /// 统计访问量
    /// 1. Statistics(间隔单位，间隔周期)   d:天 ww:周 m:月 yyyy:年 ,  1
    /// 2. Statistics(起始日期，结束日期)   
    /// </summary>
    public class Custom_Statistics : PInside
    {
        #region 参数成员
        /// <summary>
        /// 起始日期
        /// </summary>
        DateTime StartDate = DateTime.MinValue;
        /// <summary>
        /// 结束日期
        /// </summary>
        DateTime EndDate = DateTime.MinValue;
        /// <summary>
        /// 间隔单位
        /// </summary>
        string IntervalChar = "d";
        /// <summary>
        /// 间隔周期
        /// </summary>
        int IntervalNum = 1;
        #endregion

        #region 重写的方法
        protected override void SplitFormatParas(string sourceParas)
        {            
            string[] paras = GetParasArray(sourceParas);
            //确定重载方法,由多到少
            /********** 2 **********/
            try
            {
                IntervalChar = Convert.ToString(paras[0]);
                IntervalNum = Convert.ToInt32(paras[1]);
                FunctionBurden = BurdenIndex.two;
                return;
            }
            catch { }
            /********** 1 **********/
            try
            {
                StartDate = Convert.ToDateTime(paras[0]);
                EndDate = Convert.ToDateTime(paras[1]);
                FunctionBurden = BurdenIndex.one;
                return;
            }
            catch { }
            
        }

        public override string ToString()
        {
            string result = string.Empty;            

            switch (FunctionBurden)
            { 
                case BurdenIndex.one:
                    result = DataEntity.tab_Statistics.CycCount(StartDate, EndDate).ToString();
                    //result = StartDate.ToString() + "," + EndDate.ToString();
                    break;
                case BurdenIndex.two:
                    result = DataEntity.tab_Statistics.CycCount(IntervalChar, IntervalNum).ToString();
                    //result = IntervalChar + "," + IntervalNum;
                    break;
            }

            return result;
        }
        #endregion
    }
}